package com.dtw.ditouwang.ui.mine;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.CommonBean;
import com.dtw.ditouwang.repositories.UserRepository;
import com.dtw.ditouwang.ui.BaseActivity;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ChangePassActivity extends BaseActivity implements View.OnClickListener {
    EditText pass,newpass,passagain;
    Button confirm;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_pass);
        enableBack();
        setTitle("修改密码");
        pass = findViewById(R.id.edit_pass);
        newpass = findViewById(R.id.edit_pass_new);
        passagain = findViewById(R.id.edit_pass_new_again);
        confirm = findViewById(R.id.buttn_confirm);
        confirm.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        webApi.updatePass(UserRepository.getInstance().getUserID(), pass.getText().toString(), newpass.getText().toString(), passagain.getText().toString()).enqueue(new Callback<CommonBean>() {
            @Override
            public void onResponse(Call<CommonBean> call, Response<CommonBean> response) {
                showToast(response.body().getMsg());
                if(response.body().isResult()){
                    finish();
                }
            }

            @Override
            public void onFailure(Call<CommonBean> call, Throwable t) {

            }
        });
    }
}
